package com.lz.football.module.sign.item
{
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.LoginEvent;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.LItem;
	import lz.controls.managers.TipsManager;

	/**
	 *签到奖励item 
	 * @author lake
	 * 
	 */	
	public class LoginSignAwardItem extends LItem implements IComponent
	{
		/**
		 * 领取奖励状态
		 * frame
		 * 1 领取按钮
		 * 2 领取按钮 灰色
		 * 3 已领取状态
		 */		
		public var getBtnMc :MovieClip;
		/**
		 *签到描述 
		 */		
		public var txtDesc		:TextField;
		/**
		 * 签到天数
		 */		
		public var txtSignDay 	:TextField;
		/**
		 *奖励mc 
		 */		
		public var awardMc		:MovieClip;
		/**
		 *奖励类型
		 * 0 每天
		 * 1 5天
		 * 2 12天
		 * 3 26天 
		 */		
		private var _awardType	:int;
		/**
		 *奖励天数 
		 */		
		public var awardDays	:int;
		
		public function LoginSignAwardItem()
		{
			super();
		}
		/**
		 *获取设置奖励类型 
		 * @param value
		 * 
		 */		
		public function set awardType(value :int):void
		{
			_awardType = value;
			if(awardMc)
			{
				awardMc.gotoAndStop(_awardType);
			}
		}
		public function get awardType():int
		{
			return _awardType;
		}
		/**
		 * 设置数据
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			_data = value;
			setShowData();
		}
		/**
		 *设置界面数据 
		 * 
		 */		
		private function setShowData():void
		{
			switch(awardType)
			{
				case 0:
				{
					if(_data.is_get_today == 1)
					{
						getBtnMc.gotoAndStop(3);
						getBtnMc.mouseChildren = false;
						getBtnMc.mouseEnabled = false;
					}
					else if(_data.is_get_today == 0)
					{
						getBtnMc.gotoAndStop(2);
						getBtnMc.mouseChildren = false;
						getBtnMc.mouseEnabled = false;
					}
					else
					{
						getBtnMc.gotoAndStop(1);
						getBtnMc.mouseChildren = true;
						getBtnMc.mouseEnabled = true;
					}
					break;
				}
				case 1:
				case 2:
				case 3:
				{
					txtDesc.text = "" + awardDays + "";
					break;
				}
			}
			if(txtSignDay)
			{
				txtSignDay.text = _data.sign_days + "/" + awardDays + "";
				if(_data.sign_days < awardDays)//未到达条件
				{
					getBtnMc.gotoAndStop(2);
					getBtnMc.mouseChildren = false;
					getBtnMc.mouseEnabled = false;
				}
				else
				{
					if(_data.getDayFlags[awardType - 1] == 1)//已经领取
					{
						getBtnMc.gotoAndStop(3);
						getBtnMc.mouseChildren = false;
						getBtnMc.mouseEnabled = false;
					}
					else//可以领取
					{
						getBtnMc.gotoAndStop(1);
						getBtnMc.mouseChildren = true;
						getBtnMc.mouseEnabled = true;
					}
				}
			}
		}
		/**
		 * 获取数据
		 * @return 
		 * 
		 */		
		override public function get data():*
		{
			return _data;
		}
		/**
		 *初始化 
		 * 
		 */		
		public function initUI(view :Object = null):void
		{
			_symbolSkin = view as MovieClip;
			if(_symbolSkin == null)
			{
				return;
			}
			txtDesc = _symbolSkin.txtDesc;
			txtSignDay = _symbolSkin.txtSignDay;
			getBtnMc = _symbolSkin.getBtnMc;
			awardMc = _symbolSkin.awardMc;
			addEvtListener();
		}
		/**
		 *更新数据 
		 * 
		 */		
		public function updateData():void
		{
			setShowData();
		}
		/**
		 *注册事件 
		 * 
		 */		
		public function addEvtListener():void
		{
			getBtnMc.addEventListener(MouseEvent.CLICK,getAwardHandler);
			_symbolSkin.addEventListener(MouseEvent.ROLL_OVER,onRollOver);
			_symbolSkin.addEventListener(MouseEvent.ROLL_OUT,onRollOut);
		}
		private function onRollOut(event:MouseEvent):void
		{
			TipsManager.hide();
		}
		private function onRollOver(event:MouseEvent):void
		{
			//TipsManager.show(TipsConst.BASETIPS,{tip:_data.tips[awardType]},15,15);
		}
		/**
		 *获取奖励 handler 
		 * @param e
		 * 
		 */		
		private function getAwardHandler(e :Event):void
		{
			AppEventDispatcher.getInstance().dispatchEvent(new LoginEvent(LoginEvent.USER_GET_SIGN_AWARD,(awardType + 1)));
		}
		/**
		 *删除事件 
		 * 
		 */		
		public function removeEvtListener():void
		{
			getBtnMc.removeEventListener(MouseEvent.CLICK,getAwardHandler);
			_symbolSkin.removeEventListener(MouseEvent.ROLL_OVER,onRollOver);
			_symbolSkin.removeEventListener(MouseEvent.ROLL_OUT,onRollOut);
		}
		/**
		 *销毁 
		 * 
		 */		
		public function destroyView():void
		{
			removeEvtListener();
		}
	}
}